package com.tianpengtech.admin.appsetting;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Model;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.admin.AbstractAdmin;
import com.tianpengtech.common.model.appsetting.AppSetting;
import com.tianpengtech.common.search.EqualCondition;
import com.tianpengtech.common.search.LikeCondition;
import com.tianpengtech.common.search.QueryConstructor;

public class AppSettingAdminServiceImpl extends AbstractAdmin{

	@Override
	public void beforeAdd(Model<?> model) throws ValidateException {

	}

	@Override
	public void beforeQueryById(Model<?> model, int id) {

	}

	@Override
	public void beforeUpdate(Model<?> model) throws ValidateException {

	}

	@Override
	public void beforeDelete(Model<?> model) {

	}

	@Override
	public void builderSQLExpected(Model< ? > model,
			QueryConstructor queryConstruct, Map< String, Object > params) {

		int cateogry = model.getInt(AppSetting.CATEOGRY);
		String name = model.getStr(AppSetting.NAME);
		if(cateogry>0){
			queryConstruct.and(new EqualCondition(AppSetting.CATEOGRY, cateogry));
		}
		if(StringUtils.isNotEmpty(name)){
			queryConstruct.and(new LikeCondition(AppSetting.NAME, "%"+name+"%"));
		}
	}

	@Override
	public String tableName() {
		return AppSetting.dao.tableName();
	}

}